<?php
/**
 * QQAS - share your knowledge to the world!
 *
 * @author		xiaochong0302 <xiaochong0302@gmail.com>
 * @copyright	Copyright (c) 2011, Koogua Studio.
 * @license		http://www.qqas.org/user_guide/license.html
 * @link		http://www.qqas.org
 * @since		Version 1.0
 * @filesource
 */


class BlacklistModel extends Model
{
	

	/**
	 * 缓存非法的用户名
	 *
	 */
	public function cacheUsernameBlacklist()
	{
		$map = array('type' => 'username');
		$blacklist = $this->where($map)->select();
		if (!empty($blacklist))
        {
            $seperator = $regx = '';
            foreach ($blacklist as $value)
            {
            	$temp = str_replace(array('*'), array('\w+'), $value['value']);
            	$regx .= $seperator . $temp;
            	$seperator = '|';
            }
        }
        F('cache_username_blacklist', $regx);
	}
	
	
	/**
	 * 缓存非法的邮箱地址
	 *
	 */
	public function cacheEmailBlacklist()
	{
        $map = array('type' => 'email');
        $blacklist = $this->where($map)->select();
        if (!empty($blacklist))
        {
            $seperator = $regx = '';
            foreach ($blacklist as $value)
            {
            	$temp = str_replace(array('*'), array('\w+'), $value['value']);
            	$regx .= $seperator . $temp;
            	$seperator = '|';
            }
        }
        F('cache_email_blacklist', $regx);
	}
	
	
	/**
	 * 缓存被禁止的IP地址
	 *
	 */
    public function cacheIpBlacklist()
    {
        $where = array(
        	'exprie_time' => array('gt', 0),
        	'expire_time' => array('lt', time()),
        );
        $this->where($where)->delete();

        $map = array('type' => 'ip');
        $blacklist = $this->where($map)->select();
        if (!empty($blacklist))
        {
            $seperator = $regx = '';
            foreach ($blacklist as $value)
            {
            	$temp = str_replace(array('.','*'), array('\.','\d+'), $value['value']);
            	$regx .= $seperator . $temp;
            	$seperator = '|';
            }
        }
        F('cache_ip_blacklist', $regx);
    }

}


/* End of file BlacklistModel.class.php */
/* Location: ./App/Lib/Model/BlacklistModel.class.php */